import { net, protocol } from 'electron';
import * as path from 'path';
import { URL, pathToFileURL } from 'url';

export default (scheme: string) => {
  protocol.handle(scheme, (request) => {
    let pathName = new URL(request.url).pathname;
    pathName = decodeURI(pathName); // Needed in case URL contains spaces

    return net.fetch(pathToFileURL(path.join(__dirname, pathName)).toString());
  });
};
